//
//  SXTTabBarViewController.h
//
//
//  Created by ma c on 16/8/18.
//
//

#import "SXTMyViewController.h"
#import "SXTMyMessageHeadView.h"
#import "SXTMyMessageTableView.h"
#import "SXTMyMessageTableViewCell.h"
#import "SXTLandingViewController.h"
#import "SXTLoginViewController.h"
#import "SXTLoginView.h"
#import <Masonry.h>

@interface SXTMyViewController ()
//顶部背景图片
@property (nonatomic,strong) SXTMyMessageHeadView * headView;
//功能列表
@property (nonatomic,strong) SXTMyMessageTableView * messageTable;

@end

@implementation SXTMyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.edgesForExtendedLayout = 0;
    self.view.backgroundColor = MainColor;
    [self.view addSubview:self.messageTable];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [_messageTable reloadData];
    [_headView reloadHeadView];
}

#pragma mark - 初始化
-(SXTMyMessageHeadView *)headView{

    if (!_headView) {
        _headView = [[SXTMyMessageHeadView alloc]initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, 160)];
        __weak typeof(self) weakSelf = self;
        
        _headView.landingBlock = ^(){
            SXTLandingViewController * landingView = [[SXTLandingViewController alloc]init];
            [weakSelf.navigationController pushViewController:landingView animated:YES];
        };
        _headView.loginBtnBlock = ^(){
            SXTLoginViewController *loginView = [[SXTLoginViewController alloc]init];
            [weakSelf.navigationController pushViewController:loginView animated:YES];
        };
    }
    return _headView;
}

-(SXTMyMessageTableView *)messageTable{

    if (!_messageTable) {
        _messageTable = [[SXTMyMessageTableView alloc]initWithFrame:CGRectMake(0, 0, VIEW_WIDTH , VIEW_HEIGHT) style:(UITableViewStylePlain)];
        __weak typeof(self) weakSelf = self;
        _messageTable.exitblock = ^(){
        
            [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"ISLOGIN"];
            [weakSelf.messageTable reloadData];
            [weakSelf.headView reloadHeadView];
        };
        _messageTable.tableHeaderView = self.headView;
        
    }
    return _messageTable;
}



@end
